import torch
import torch.nn as nn
import torchvision
from torch.nn import MaxPool2d
#输入为数据库
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

dataset = torchvision.datasets.CIFAR10("./dataset",train=False,transform=torchvision.transforms.ToTensor(),download=True)
dataloader = DataLoader(dataset,64)


class MyModule(nn.Module):
    def __init__(self):
        super(MyModule, self).__init__()
        self.maxpool2d = MaxPool2d(kernel_size=3,ceil_mode=True)

    def forward(self,input):
        output = self.maxpool2d(input)
        return output


mymodule = MyModule()
writer = SummaryWriter("maxpool_logs")
step = 0
for data in dataloader:
    imgs,targets = data
    writer.add_images("input", imgs, step)
    output = mymodule(imgs)
    writer.add_images("output",output,step)
    step = step+1
writer.close()







#输入为具体的图像二维矩阵
# input = torch.tensor([[1,2,0,3,1],
#                       [0,1,2,3,1],
#                       [1,2,1,0,0],
#                       [5,2,3,1,1],
#                       [2,1,0,1,1]],dtype=torch.float32)
#
#
# class MyModule(nn.Module):
#     def __init__(self):
#         super(MyModule, self).__init__()
#         self.maxpool2d = MaxPool2d(kernel_size=3,ceil_mode=True)
#
#     def forward(self,input):
#         output = self.maxpool2d(input)
#         return output
#
# #最大池化的输入输出的数据个格式
# #Input:(N,C,Hin,,Win) or(C,Hin,Win)
# #Output:(N,C,Hout,Wout) or(C,Hout,Wout)
# print(input.shape)
# input = torch.reshape(input,(-1,1,5,5))
# mymodule = MyModule()
# output = mymodule(input)
# print(output.shape)
# print(output)
